# Copyright (c) 2016 OSChina.NET All Rights Reserved.
# CMake Required version
cmake_minimum_required (VERSION 2.8)
project(svnsrv)


if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
  message(FATAL_ERROR "In-source builds are not allowed.
CMake would overwrite the makefiles distributed with svnsrv.
Please create a directory and run cmake from there, passing the path
to this source directory as the last argument.
This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
Please delete them.")
endif()

if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "No build type selected, default to Debug")
  set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (default Debug)")
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
    message(STATUS "Build svnsrv on linux ")
elseif(CMAKE_SYSTEM_NAME MATCHS "Apple")
    message(STATUS "svnsrv not support build on OSX")
elseif(CMAKE_SYSTEM_NAME MATCHS "FreeBSD")
    message(STATUS "svnsrv not support build on FreeBSD")
elseif(CMAKE_SYSTEM_NAME MATCHS "Windows")
    message(STATUS "svnsrv not support build on Windows")
else()
    message(STATUS "svnsrv not support build on ${CMAKE_SYSTEM_NAME}")
endif()

if(NOT DEFINED SVNSRV_VERSION_MAJOR)
    set(SVNSRV_VERSION_MAJOR 1)
endif()
if(NOT DEFINED SVNSRV_VERSION_MINOR)
    set(SVNSRV_VERSION_MINOR 0)
endif()
if(NOT DEFINED SVNSRV_VERSION_PATCH)
    set(SVNSRV_VERSION_PATCH 0)
endif()
if(NOT DEFINED SVNSRV_VERSION_SUFFIX)
    set(SVNSRV_VERSION_SUFFIX 0)
endif()

#set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

set(CMAKE_INSTALL_PREFIX "/opt/svnsrv")

set(CPACK_PACKAGE_NAME "svnsrv")
set(CPACK_PACKAGE_VENDOR "OSChina.NET")
set(CPACK_PACKAGE_DESCRIPTION "Subversion svn protocol dynamic proxy server")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "svn dynamic proxy server")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "_CPack_")
set(CPACK_PACKAGE_VERSION "${SVNSRV_VERSION_MAJOR}.${SVNSRV_VERSION_MINOR}.${SVNSRV_VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION_MAJOR "${SVNSRV_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${SVNSRV_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${SVNSRV_VERSION_PATCH}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3.1-6)")
set(CPACK_PACKAGE_DESCRIPTION "svn dynamic proxy server")
set(CPACK_PACKAGE_CONTACT "ipvb@qq.com")
set(CPACK_DEBIAN_PACKAGE_SECTION Network)
include(CPack)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX14)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif(COMPILER_SUPPORTS_CXX11)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
# Find Boost Package
FIND_PACKAGE(Boost 1.54 COMPONENTS  system thread date_time  REQUIRED)

if(Boost_FOUND)
    message(STATUS "Found Boost")
else()
    message(FATAL_ERROR  "Not Found Boost ")
endif()

if (NOT MSVC)
    add_compile_options("-g")
    add_compile_options("-Wall")
    add_compile_options("-Wextra")
endif()




add_subdirectory(src)
